//The purpose of this dialog is to display an informational box
//displaying some relevant details of the client/employee that has changed.
//It disposes itself after waiting 3 seconds.
package project;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;

public class ConfirmDialog extends JDialog
{
	private JLabel idL = null, firstNameL = null, surnameL = null,
	passwordL = null;
	private JLabel idDispL = null, firstNameDispL = null, surnameDispL = null,
		passwordDispL = null;
	private JLabel headL = null;
	private Font font = null, italicFont = null;
	private JPanel mainP = null, topP = null, centerP = null;
				
	public ConfirmDialog(String type, String [] input)
	{
		if(input.length == 0)
		{
			return;
		}
		topP = new JPanel();
		topP.setBackground(new Color(240,230,140));
		topP.setBorder(BorderFactory.createEmptyBorder(0,0,20,0));
		centerP = new JPanel(new SpringLayout());
		centerP.setBackground(new Color(240,230,140));
		//centerP.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		headL = new JLabel("Saving Details...");
		String fontName = headL.getFont().getFontName();
		font = new Font(fontName, Font.BOLD, 14);
		Font newFont = new Font(fontName, Font.BOLD, 16);
		headL.setFont(font);
		if(type.equals("Client"))
		{
			idL = new JLabel("Client ID: ");
		}
		else
		{
			idL = new JLabel("Employee ID: ");
		}
		font = new Font(fontName, Font.BOLD, 14);
		idL.setFont(font);
		firstNameL = new JLabel("First Name: ");
		firstNameL.setFont(font);
		surnameL = new JLabel("Surname: ");
		surnameL.setFont(font);
		passwordL = new JLabel("Password: ");
		passwordL.setFont(font);
		idDispL = new JLabel(input[0]);
		idDispL.setFont(newFont);
		firstNameDispL = new JLabel(input[1]);
		firstNameDispL.setFont(newFont);
		surnameDispL = new JLabel(input[2]);
		surnameDispL.setFont(newFont);
		passwordDispL = new JLabel(input[3]);
		passwordDispL.setFont(newFont);
		topP.add(headL);
		centerP.add(idL);
		idL.setLabelFor(idDispL);
		centerP.add(idDispL);
		centerP.add(firstNameL);
		firstNameL.setLabelFor(firstNameDispL);
		centerP.add(firstNameDispL);
		centerP.add(surnameL);
		surnameL.setLabelFor(surnameDispL);
		centerP.add(surnameDispL);
		centerP.add(passwordL);
		passwordL.setLabelFor(passwordDispL);
		centerP.add(passwordDispL);
		
		SpringUtilities.makeCompactGrid(centerP,
                                        4, 2, //rows, cols
                                        6, 6,        //initX, initY
                                        5, 10);       //xPad, yPad
		
		
		this.setSize(250,300);
		this.setUndecorated(true);
		//his.setBorder(new LineBorder(
		//			Color.BLACK, 1, true));
		mainP = new JPanel(new BorderLayout());
		
		mainP.setBackground(new Color(240,230,140));
		mainP.setBorder(BorderFactory.createLineBorder(
					Color.BLACK, 3));
		
		mainP.add(topP, BorderLayout.NORTH);
		mainP.add(centerP, BorderLayout.CENTER);
		this.add(mainP);
		Dimension sSize = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension fSize = this.getSize();
		int newX = (sSize.width - fSize.width);
		int newY = (0); // set new position
		this.setLocation(newX, newY);
		new ConfirmDialogThread(this);
	}

}

class ConfirmDialogThread extends Thread
{
	ConfirmDialog cd = null;
	
	public ConfirmDialogThread(ConfirmDialog cd)
	{
		this.cd = cd;
		this.start();
	}
	public void run()
	{
		try
		{
			String [] arr = new String[0];
			cd.show();
			Thread.sleep(4000);
			cd.dispose();
		}
		catch(InterruptedException iex)
		{
			iex.printStackTrace();
		}
	}
}

//class TestDialog
//{
//	public static void main(String [] args)
//	{
//		new ConfirmDialogThread();
//	}
//}